from tools.listNode import listToNode, nodeToList, ListNode


def addTwoNumbers(l1, l2):
    total = l1.val + l2.val
    next = total // 10
    res = ListNode(total % 10)
    if l1.next or l2.next or next != 0:
        l1 = l1.next if l1.next else ListNode()
        l2 = l2.next if l2.next else ListNode()
        l1.val = l1.val + next
        res.next = addTwoNumbers(l1, l2)
    return res


l1 = listToNode([2, 4, 3])
l2 = listToNode([5, 6, 4])
print(nodeToList(addTwoNumbers(l1, l2)))
